-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/#1032 working veto system #1033
base: develop
Are you sure you want to change the base?
Feature/#1032 working veto system #1033
Conversation
if (tokensTotalPerPlayer[player.id] > veto_tokens_per_player): | ||
raise RuntimeError(f"Player {player.id} has too many vetoes!") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not do validation of the number of tokens per player when starting the game. This validation and error raising should happen when the server receives the set_vetoes message. This is because as it is now a player could send the server more than the max amount of vetoes and then cause a game to never be able to launch.
def calculate_dynamic_tokens_per_map(self, M: float, tokens: list[int]) -> float: | ||
sorted_tokens = sorted(tokens) | ||
if (sorted_tokens.count(0) >= M): | ||
return 1 | ||
|
||
result = 1; last = 0; index = 0 | ||
while (index < len(sorted_tokens)): | ||
(index, last) = next(((i, el) for i, el in enumerate(sorted_tokens) if el > last), (len(sorted_tokens) - 1, sorted_tokens[-1])) | ||
index += 1 | ||
divider = index - M | ||
if (divider <= 0): | ||
continue | ||
|
||
result = sum(sorted_tokens[:index]) / divider | ||
upperLimit = sorted_tokens[index] if index < len(sorted_tokens) else float('inf') | ||
if (result <= upperLimit): | ||
return result | ||
|
||
raise Exception("Failed to calculate dynamic tokens per map: impossible vetoes setup") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly here we are throwing an exception based on user input so a user could craft a veto selection that could cause the majority of games to fail to start. It would be better to have some default value rather than throwing an exception.
also idk how least_common should work |
Working on #1032
I need some feedback, what is right, what is wrong, what needs to be changed, etc